
from WtfEngine import *;
import WtfAi;

class Breeder:
	def __init__(self, popSize, neurons, inputMap, outputMap):
		self.popSize = popSize;
		self.population = [];
		self.currentGen = 0;
		self.numMutations = 1;
		
		vin = UnsignedArray();
		vin.extend(inputMap);
		out = UnsignedArray();
		out.extend(outputMap);
		
		i = 0;
		while i < popSize:
			n = WtfAi.GeneticNeuralNetwork("gnn_breeder-0-" + str(i), neurons, vin, out);
			n.Randomize();
			self.population.append(n);
			i = i + 1;
	
	def NextGeneration(self, parent, save):
		self.population = [parent];
		self.currentGen = self.currentGen + 1;
	
		if save:
			parent.SaveToFile(parent.name + ".txt");
			
		i = 1;
		while i < self.popSize:
			n = parent.Clone("gnn_breeder-" + str(self.currentGen) + "-" + str(i));
			
			j = 0;
			while j < self.numMutations:
				n.Mutate();
				j = j + 1;
			
			self.population.append(n);
			i = i + 1;
	
	